package com.yy.jhl.ui.manager.presenter;

import com.google.gson.Gson;
import com.yy.common.commonutils.SPUtils;
import com.yy.jhl.api.Api;
import com.yy.jhl.api.RxSubscriber;
import com.yy.jhl.app.AppConstant;
import com.yy.jhl.bean.LoginInfo;
import com.yy.jhl.bean.MessageListInfo;
import com.yy.jhl.ui.manager.contract.MessageListContract;

import okhttp3.FormBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/**
 * Created by libingn on 2017/12/14.
 */

public class MessageListPresenter extends MessageListContract.Presenter {
    @Override
    public void getMessageList(int start,int limit, int is_history,boolean isDialog) {
        mRxManage.addSubscription(Api.getDefault().getMessageList(start,limit,is_history), new RxSubscriber<ResponseBody>(mContext,isDialog) {
            @Override
            protected void _onNext(String result) {
                MessageListInfo messageListInfo = new Gson().fromJson(result,MessageListInfo.class);
                mView.getMessageListSuccess(messageListInfo);
            }

            @Override
            protected void _onError(String message) {
                mView.getMessageListFail();
            }
        });
    }

    @Override
    public void setMessageReaded() {
        RequestBody requestBody = new FormBody.Builder()
            .build();
        mRxManage.addSubscription(Api.getDefault().setMessageReaded(requestBody), new RxSubscriber<ResponseBody>(mContext,false) {
            @Override
            protected void _onNext(String result) {
                mView.getMessageResult(true);
            }

            @Override
            protected void _onError(String message) {
                mView.getMessageResult(false);
            }
        });
    }
}
